package com.chris.datacnter.service;

import com.chris.datacnter.dao.DcRuntimeDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Service
public class SnowFlakeDataCenterAutoService {
    ScheduledExecutorService worker = new ScheduledThreadPoolExecutor(1);
    @Autowired
    DcRuntimeDAO dcRuntimeDAO;

    public SnowFlakeDataCenterAutoService() {
        //-----------------------------------------------------------
        worker.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                doCheck();
            }
        }, 30, 60 * 1, TimeUnit.SECONDS);//每？秒自动更新状态
        //---------------------------------------------------------

    }


    private void doCheck() {
        dcRuntimeDAO.docheck();
    }
}
